﻿using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Metal : Material
{
    Color albedo;
    public Metal(Color a,float f=0) { albedo = a; fuzz = f < 1 ? f : 1; }
    public float fuzz= 1f;
    public override bool scatter(Ray ray, HitRecord record, ref Color attaenuation, ref Ray scattered)
    {
        var target = ReflectionPoint(ray.normalDirection, record.normal);
        scattered = new Ray(record.p, target + fuzz * _M.GetRandomPointInUnitSphere());
        attaenuation = albedo;
        return Vector3.Dot(scattered.direction, record.normal) > 0;
    }

    private Vector3 ReflectionPoint(Vector3 vIn , Vector3 normal)
    {
        return vIn - 2 * Vector3.Dot(vIn, normal) * normal;
    }
}
